package pure.csw.activemq.rediliverAndDeathletter;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.RedeliveryPolicy;
import org.apache.activemq.ScheduledMessage;
import pure.csw.common.Constant;

import javax.jms.*;
import java.io.IOException;

public class Produce {
    public static void main(String[] args) throws JMSException, InterruptedException, IOException {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(Constant.URL);
        Connection connection = factory.createConnection();
        connection.start();
        //开启一次会话，非事务，自动确认
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        //消息以队列的方式存储
        Queue queue = session.createQueue(Constant.QUEUENAME);
        //创建文本消息
        TextMessage message = session.createTextMessage();
        message.setText("the message");
        //创建消息的生产者
        MessageProducer producer = session.createProducer(queue);
        System.out.println("producer send message start");
        //发送消息，持久，优先级为4，存活时间为5秒
        producer.send(message);
        //等待消息的发送完成
        Thread.sleep(3000);
        System.out.println("producer send message over");
        //关闭资源
        producer.close();
        session.close();
        connection.close();
    }
}
